// -*- C++ -*-

#pragma once
#ifndef INCLUDEOS_COMMON_HEADER
#define INCLUDEOS_COMMON_HEADER

#if !defined(__cplusplus)
#error "IncludeOS must be built with a C++ compiler"
#endif

#ifdef ARCH_X86
static_assert(sizeof(void*) == 4, "Pointer must match arch");
#endif
#ifdef ARCH_X64
static_assert(sizeof(void*) == 8, "Pointer must match arch");
#endif

/* BOCHS Break point */
#define BREAK() __asm__ volatile("xchg %bx,%bx");

/* debugging macros */
#include "debug"
#include "info"

// LIKELY/UNLIKELY
#include "branch_prediction"

#include <gsl/gsl>

/* Define our own termination policy for contract   */
/* violation to generate relevant information about */
/* the reason for termination.                      */
#if defined(OS_TERMINATE_ON_CONTRACT_VIOLATION)

#include <cstdlib>

#undef Expects
#undef Ensures
extern void __expect_fail(const char*, const char*, int line, const char*);

#define Expects(x) ((void)((x) || (__expect_fail("Expects failed: "#x, __FILE__, __LINE__, __func__),0)))
#define Ensures(x) ((void)((x) || (__expect_fail("Ensures failed: "#x, __FILE__, __LINE__, __func__),0)))

#endif //< defined(OS_TERMINATE_ON_CONTRACT_VIOLATION)

namespace os {
// parameter for noexcept specifier when bypassing noexcept for testing
#if defined(TEST)
  constexpr bool hard_noexcept = false;
#else
  constexpr bool hard_noexcept = true;
#endif

}
#endif //< INCLUDEOS_COMMON_HEADER
